﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;

namespace Bronze.ReportBuilder
{
    public static class Extensions
    {
        public static object GetDefaultValue(this PropertyDescriptor prop)
        {
            var defaultValueAttrType=typeof(DefaultValueAttribute);
            foreach (var item in prop.Attributes)
            {
                if (defaultValueAttrType.IsAssignableFrom(item.GetType()))
                {
                    var defaultValAttr=item as DefaultValueAttribute;
                    if (defaultValAttr!=null)
                    {
                        return defaultValAttr.Value;
                    }
                }
            }
            return null;
        }

        public static bool IsNull(this object o)
        {
            if (o == null)
            {
                return true;
            }

            if (o.Equals(DBNull.Value))
            {
                return true;
            }

            if (o is string)
            {
                return string.IsNullOrEmpty((string)o);
            }
            else if (o is Guid || o is Guid?)
            {
                if (o.ToString() == Guid.Empty.ToString())
                {
                    return true;
                }
            }
            return false;

        }
    }
}